<template>
	<view>
		<view class="" style="width: 100%;padding: 20rpx 20rpx;">
			<view class="" style="width: 100%;padding: 0 20rpx;border-radius: 20rpx;background-color: #ffffff;">
				<view class="" @click="headerImage(userInfo.logoPath)"
					style="width: 100%;height: 100rpx;border-bottom: 1px solid #ECECEC;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<view>头像</view>
					<view style="display: flex;flex-direction: row;align-items: center;">
						<view class="" style="width: 70rpx;height: 70rpx;border-radius: 50%;margin-right: 20rpx;overflow: hidden;">
							<image style="width: 100%;height: 100%;" :src="FILE_SRC_PATH + userInfo.logoPath" mode=""></image>
						</view>
						<view class="" style="width:35rpx; height: 35rpx;">
							<image src="../../../static/img/myPage/right.png" style="width: 100%;height: 100%;" mode="">
							</image>
						</view>
					</view>
				</view>
				<view class="" @click="updataName"
					style="width: 100%;height: 100rpx;border-bottom: 1px solid #ECECEC;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<view>昵称</view>
					<view style="display: flex;flex-direction: row;align-items: center;">
						<view class="" style="margin-right: 10rpx;font-size: 30rpx;">{{userInfo.shopName}}
						</view>
						<view class="" style="width:35rpx; height: 35rpx;">
							<image src="../../../static/img/myPage/right.png" style="width: 100%;height: 100%;" mode="">
							</image>
						</view>
					</view>
				</view>
				<view class="" @click="updataAddress"
					style="width: 100%;height: 100rpx;border-bottom: 1px solid #ECECEC;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<view>店铺地址</view>
					<view style="display: flex;flex-direction: row;align-items: center;">
						<view class="gonggao" style="margin-right: 10rpx;font-size: 30rpx;max-width: 400rpx;">{{userInfo.address}}
						</view>
						<view class="" style="width:35rpx; height: 35rpx;">
							<image src="../../../static/img/myPage/right.png" style="width: 100%;height: 100%;" mode="">
							</image>
						</view>
					</view>
				</view>
				<view class="" @click="updataTime"
					style="width: 100%;height: 100rpx;border-bottom: 1px solid #ECECEC;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<view>营业时间</view>
					<view style="display: flex;flex-direction: row;align-items: center;">
						<view class="" style="margin-right: 10rpx;font-size: 30rpx;">
							<view class="">{{optionTime[0].beginTime}} - {{optionTime[0].endTime}} <text
									v-if="optionTime.length>1">...</text></view>
						</view>
						<view class="" style="width:35rpx; height: 35rpx;">
							<image src="../../../static/img/myPage/right.png" style="width: 100%;height: 100%;" mode="">
							</image>
						</view>
					</view>
				</view>
				<view class=""
					style="width: 100%;height: 100rpx;border-bottom: 1px solid #ECECEC;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<view>营业状态</view>
					<view style="display: flex;flex-direction: row;align-items: center;">
						<view class="" style="margin-right: 10rpx;color: red;font-size: 30rpx;">
							<view class="stateYE" :style="{color:userInfo.openStatus == 0 ? '#6CE26C' : 'red'}"> <view class="state" :style="{background:userInfo.openStatus == 0 ? '#6CE26C' : 'red'}"> </view> {{userInfo.openStatus == 0 ? '营业中' : '休息中'}}</view>
						</view>
						<!-- <view class="" style="width:35rpx; height: 35rpx;">
							<image src="../../../static/img/myPage/right.png" style="width: 100%;height: 100%;" mode="">
							</image>
						</view> -->
						<u-switch style="margin-right: 20rpx;" @change="switchChange"  inactive-color="red" v-model="checkedState"></u-switch>
					</view>
				</view>
				<view class="" @click="updataGao"
					style="width: 100%;height: 100rpx;border-bottom: 1px solid #ECECEC;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<view>店铺公告</view>
					<view style="display: flex;flex-direction: row;align-items: center;">
						<view class="gonggao" style="margin-right: 10rpx;font-size: 30rpx;max-width: 200rpx;height: 100%;">{{userInfo.notice}}
						</view>
						<view class="" style="width:35rpx; height: 35rpx;">
							<image src="../../../static/img/myPage/right.png" style="width: 100%;height: 100%;" mode="">
							</image>
						</view>
					</view>
				</view>
			</view>
			<view class=""
				style="width: 100%;padding: 0 20rpx;border-radius: 20rpx;background-color: #ffffff;margin-top: 40rpx;">
				<view class="" @click="intoXiuGai"
					style="width: 100%;height: 120rpx;border-bottom: 1px solid #ECECEC;display: flex;flex-direction: row;align-items: center;justify-content: space-between;">
					<view>修改密码</view>
					<view class="" style="width:35rpx; height: 35rpx;">
						<image src="../../../static/img/myPage/right.png" style="width: 100%;height: 100%;" mode="">
						</image>
					</view>
		
				</view>
			</view>
			<view class="" style="margin-top: 150rpx;padding: 0 20rpx;">
				<u-button @click="tuichu" type="primary">退出账号</u-button>
			</view>
		</view>
		<u-modal v-model="show1" content="确认要退出账号？" title="提示" show-cancel-button @confirm="confirm1" @cancel="cancel"></u-modal>
		<u-toast ref="uToast" />
		<u-modal v-model="show" title="修改密码" show-cancel-button @confirm="confirm" >
			<view class="" style="height: 50rpx;width: 100%;"></view>
			<u-field v-model="newPassword" label="密码" placeholder="请输入新密码">
			</u-field>
			<view class="" style="height: 50rpx;width: 100%;"></view>
		</u-modal>
		<u-modal v-model="showName" title="修改昵称" show-cancel-button @confirm="confirmName" >
			<view class="" style="height: 50rpx;width: 100%;"></view>
			<u-field v-model="newName" label="昵称" placeholder="请输入新昵称">
			</u-field>
			<view class="" style="height: 50rpx;width: 100%;"></view>
		</u-modal>
		<u-modal v-model="addressShow" title="修改地址" show-cancel-button @confirm="confirmAddress" >
			<view class="" style="height: 50rpx;width: 100%;"></view>
			<u-field v-model="newAddress" label="地址" placeholder="请输入新地址">
			</u-field>
			<view class="" style="height: 50rpx;width: 100%;"></view>
		</u-modal>
		<u-modal v-model="GonggaoShow" title="修改公告" show-cancel-button @confirm="confirmGonggao" >
			<view class="" style="height: 50rpx;width: 100%;"></view>
			<u-field v-model="newgonggao" label="公告" placeholder="请输入新公告">
			</u-field>
			<view class="" style="height: 50rpx;width: 100%;"></view>
		</u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show1: false,
				show:false,
				showName:false,
				addressShow:false,
				GonggaoShow:false,
				FILE_SRC_PATH: this.sysConstant.FILE_SRC_PATH,
				userInfo:{},
				optionTime: [],
				checkedState:'',
				newPassword:'',
				newName:'',
				newAddress:'',
				newgonggao:''
			}
		},
		onShow() {
			this.getInfo()
			this.getTime()
		},
		methods: {
			switchChange(e){
				let openStatus = ''
				if(e){
					openStatus = 0
				}else{
					openStatus = -1
				}
				console.log(e);
				this.$u.put('/life/shop/update', {
					openStatus: openStatus
				}).then(res => {
					console.log(res)
					if (res.success) {
						this.$refs.uToast.show({
							title: '修改成功',
							type: 'success',
						})
						this.getInfo()
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
						})
					}
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
			tuichu(){
				uni.setStorageSync('phone', '')
				uni.setStorageSync('password', '')
				this.show1 = true;
			},
			confirm1() {
				getApp().globalData.token = ''
				uni.redirectTo({
					url: '/pages/common/login'
				})
			},
			confirmName(){
				this.$u.put('/life/shop/update', {
					shopName: this.newName
				}).then(res => {
					console.log(res)
					if (res.success) {
						this.$refs.uToast.show({
							title: '修改成功',
							type: 'success',
						})
						this.getInfo()
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
						})
					}
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
			confirmAddress(){
				this.$u.put('/life/shop/update', {
						address: this.newAddress
					}).then(res => {
						console.log(res)
						if (res.success) {
							this.$refs.uToast.show({
								title: '修改成功',
								type: 'success',
							})
							this.getInfo()
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error',
							})
						}
					}).catch(() => {
						this.$refs.uToast.show({
							title: "请求失败",
							type: 'error',
						})
					})
				
			},
			cancel() {
				this.$refs.uToast.show({
					title: "已取消",
					type: 'warning',
				})
			},
			headerImage(e){
				uni.navigateTo({
					url:'/pages/mySonPage/headerImage/headerImage?logoPath='+e
				})
			},
			updataName(){
				// uni.navigateTo({
				// 	url:'/pages/mySonPage/updataName/updataName'
				// })
				this.showName = true
			},
			updataAddress(){
				// uni.navigateTo({
				// 	url:'/pages/mySonPage/updataAddress/updataAddress'
				// })
				this.addressShow = true
			},
			updataTime(){
				uni.navigateTo({
					url:'/pages/mySonPage/updataTime/updataTime'
				})
			},
			confirmGonggao(){
				this.$u.put('/life/shop/update', {
						notice: this.newgonggao
					}).then(res => {
						console.log(res)
						if (res.success) {
							this.$refs.uToast.show({
								title: '修改成功',
								type: 'success',
							})
							this.getInfo()
						} else {
							this.$refs.uToast.show({
								title: res.msg,
								type: 'error',
							})
						}
					}).catch(() => {
						this.$refs.uToast.show({
							title: "请求失败",
							type: 'error',
						})
					})
			},
			updataGao(){
				// uni.navigateTo({
				// 	url:'/pages/mySonPage/updataGao/updataGao'
				// })
				this.GonggaoShow = true
			},
			intoXiuGai(){
				this.show = true
			},
			//修改密码
			confirm(){
				this.$u.put('/life/shop/user/changShopPass', {
					password: this.newPassword
				}).then(res => {
					console.log(res)
					if (res.success) {
						this.$refs.uToast.show({
							title: '修改成功',
							type: 'success',
						})
						this.getInfo()
					} else {
						this.$refs.uToast.show({
							title: res.msg,
							type: 'error',
						})
					}
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
			//获取店铺基本信息
			getInfo() {
				this.$u.get('/authorize/life/shop/info', {}).then(res => {
					console.log(res)
					if (res.success) {
						this.userInfo = res.data
						console.log(this.userInfo);
						if(this.userInfo.openStatus == 0){
							this.checkedState = true
						}else{
							this.checkedState = false
						}
						this.newName = this.userInfo.shopName
						this.newAddress = this.userInfo.address
						this.newgonggao = this.userInfo.notice
						// this.mobile = this.userInfo.phone
					} else {
						// this.$refs.uToast.show({
						// 	title: res.msg,
						// 	type: 'error',
						// })
					}
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
			//获取店铺营业时间
			getTime() {
				this.$u.get('life/shop/time/page', {}).then(res => {
					console.log("我是营业时间");
					console.log(res)
					this.optionTime = res.list
					console.log('6666699999988888');
					console.log(this.optionTime);
			
				}).catch(() => {
					this.$refs.uToast.show({
						title: "请求失败",
						type: 'error',
					})
				})
			},
		}
	}
</script>

<style>
.gonggao{
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		/* 这里的数字表示显示的行数，可以根据需要调整 */
		overflow: hidden;
		text-overflow: ellipsis;
	}
</style>
